# 第三方requests 模块
import requests

# get 请求
# req = requests.get('https://www.baidu.com', params={
#     's': 'car_back'
# })

# print(req.url)
# print(req.status_code)
# print(req.text)

# post 

# api_url = 'https://m.ctrip.com/restapi/soa2/18622/queryFuzzyCityList.json?_fxpcqlniredt=09031156210480907966'

# params = {"head":{"cid":"09031156210480907966","ctok":"","cver":"1.0","lang":"01","sid":"8888","syscode":"09","auth":None,"extension":[{"name":"partner","value":"zhixing"},{"name":"aid","value":"30613"},{"name":"sid","value":"1458119"}],"xsid":""},"reqhead":{"protocol":"http:","appid":100019513,"host":"m.ctrip.com","locale":"zh-cn","cury":"cny","channelid":5,"biztype":32,"pttype":17,"ptgroup":17,"sf":"h5","cid":"09031156210480907966","os":"","mode":"web","gps":{},"token":"","wlver":"0.202001171542","stntype":0,"ubt":{"pageid":10650033311,"pvid":175,"sid":26,"vid":"1566972380685.19s445n"},"union":{"sid":"1693366","aid":"66672","ouid":""}},"key":"aa","maxcount":20,"pttype":17,"ptgroup":17}

# rst = requests.post(api_url, json=params)

# print(rst.json())

# print(req.cookies['ticket'])

api_url = 'http://localhost:3000/set_cookie'

params = {
    'auth': 'sfsdfsdfsdf'
}

# rst = requests.post(
#     api_url,
#     json=params,
#     timeout=3
# )

# print(rst.cookies['auth'])

def api_post(url, **kw):
    print(kw['json'])
    rst = requests.post(
        url,
        **kw,
        timeout=3 # 3s 超时
    )
    return rst

r = api_post(api_url, json=params)

print(r.json())
print(r.cookies['auth'])